package com.example.beautymakeup.controller;

import com.example.beautymakeup.dao.InformationDao;
import com.example.beautymakeup.domain.Code;
import com.example.beautymakeup.domain.Result;
import com.example.beautymakeup.pojo.Information;
import com.example.beautymakeup.service.InformationService;
import com.example.beautymakeup.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/info")
public class InformationController {
    @Autowired
    private InformationService informationService;

    @GetMapping("/public")
    public Result get() throws Exception {
        Information information = informationService.get();
        if (information != null){
            return new Result(Code.GET_OK,"获取成功",information);
        }return new Result(Code.GET_ERR,"获取失败");
    }

    @PutMapping
    public Result update(@RequestHeader("Shop_token") String token,@RequestBody Information information) throws Exception {
        boolean update = informationService.update(token, information);
        if (update){
            return new Result(Code.UPDATE_OK,"修改成功");
        }return new Result(Code.UPDATE_ERR,"修改失败");
    }
}
